package com.hlz.fastnote

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.drawerlayout.widget.DrawerLayout
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.left_item.view.*

class LeftAdapter(val context: Context, val mDrawerLayout: DrawerLayout) : BaseAdapter<Note>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val v= LayoutInflater.from(context).inflate(R.layout.left_item,parent,false)
        return ViewHolder(v)
    }


    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        mList[position]?.let {
            holder.itemView.tvTitle.text = it.title
            holder.itemView.tvTime.text = it.time.time("yyyy-MM-dd HH:mm:ss")
            holder.itemView.setOnClickListener { v->
                val intent = Intent(context,DetailNoteActivity::class.java).apply {
                    putExtra("Note",it)
                }
                context.startActivity(intent)
                mDrawerLayout.closeDrawers()
            }
        }
    }
}